package com.example.anytest.gpsDemo.gps;

import android.location.Location;
import android.location.LocationListener;
import android.location.LocationProvider;
import android.os.Bundle;

/**
 * Created by zhwp on 2018/5/9.
 */

public class GpsLocation implements LocationListener {
	private GpsLocationListener mGpsLocationListener;
	
	public GpsLocation(GpsLocationListener gpsLocationListener) {
		this.mGpsLocationListener = gpsLocationListener;
	}
	
	@Override
	public void onLocationChanged(Location location) {
		if (location != null) {
			mGpsLocationListener.UpdateLocation(location);
		}
	}
	
	@Override
	public void onStatusChanged(String provider, int status, Bundle extras) {
		mGpsLocationListener.UpdateStatus(provider, status, extras);
		switch (status) {
			case LocationProvider.AVAILABLE :
				mGpsLocationListener.UpdateGPSProviderStatus(GpsProviderStatus.GPS_AVAILABLE);
				break;
			case LocationProvider.OUT_OF_SERVICE :
				mGpsLocationListener.UpdateGPSProviderStatus(GpsProviderStatus.GPS_OUT_OF_SERVICE);
				break;
			case LocationProvider.TEMPORARILY_UNAVAILABLE :
				mGpsLocationListener.UpdateGPSProviderStatus(GpsProviderStatus.GPS_TEMPORARILY_UNAVAILABLE);
				break;
		}
	}
	
	@Override
	public void onProviderEnabled(String provider) {
		mGpsLocationListener.UpdateGPSProviderStatus(GpsProviderStatus.GPS_ENABLED);
	}
	
	@Override
	public void onProviderDisabled(String provider) {
		mGpsLocationListener.UpdateGPSProviderStatus(GpsProviderStatus.GPS_DISABLED);
	}
}
